package tum0r.image;

import java.awt.image.BufferedImage;

/**
 * 获取图片的反色图片
 * ClassName: Inverse
 * Author: tum0r
 * Time: 2020/4/13 20:03
 */
public class Inverse extends ImageBase {

    /**
     * 反色图片
     * @param image 要反色的图片BufferedImage对象
     * @return 反色后的图片BufferedImage对象
     */
    @Override
    public BufferedImage handle(BufferedImage image) {
        BufferedImage result = null;
        if (image != null) {
            int width = image.getWidth();
            int height = image.getHeight();
            result = new BufferedImage(width, height, image.getType());
            for (int x = 0; x < width; x++) {
                for (int y = 0; y < height; y++) {
                    result.setRGB(x, y, 0xffffff - image.getRGB(x, y));
                }
            }
        }
        return result;
    }
}
